From 395c11b04fdf589e1eaf7223c62c3246b19afc6a Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Thu, 15 Feb 2007 11:16:42 +0000 Subject: [PATCH] Fix up Special:Protectedpages to use a ReverseChronologicalPager, and the new pr_id field like it should. This will improve performance, optimise, and make the data real-time as opposed to cached. --- includes/SpecialProtectedpages.php | 140 +++++++++++++++++++---------- languages/messages/MessagesEn.php | 2 + 2 files changed, 94 insertions(+), 48 deletions(-) diff --git a/includes/SpecialProtectedpages.php b/includes/SpecialProtectedpages.php index 78a26b1267..8c2c20f2f4 100644 --- a/includes/SpecialProtectedpages.php +++ b/includes/SpecialProtectedpages.php @@ -8,74 +8,120 @@ * * @addtogroup SpecialPage */ -class ProtectedPagesPage extends PageQueryPage { +class ProtectedPagesForm { + function showList( $msg = '' ) { + global $wgOut; - function getName( ) { - return "Protectedpages"; - } + $wgOut->setPagetitle( wfMsg( "protectedpages" ) ); + if ( "" != $msg ) { + $wgOut->setSubtitle( $msg ); + } - function getPageHeader() { - return '

' . wfMsg('protectedpagestext') . '

'; - } + // Purge expired entries on one in every 10 queries + if ( !mt_rand( 0, 10 ) ) { + Title::purgeExpiredRestrictions(); + } - /** - * LEFT JOIN is expensive - * - * @return true - */ - function isExpensive( ) { - return 1; - } + $pager = new ProtectedPagesPager( $this ); + $s = $pager->getNavigationBar(); - function isSyndicated() { return false; } + if ( $pager->getNumRows() ) { + $s .= ""; + } else { + $s .= '

' . wfMsgHTML( 'protectedpagesempty' ) . '

'; + } + $s .= $pager->getNavigationBar(); + $wgOut->addHTML( $s ); + } /** - * @return false + * Callback function to output a restriction */ - function sortDescending() { - return false; - } + function formatRow( $row ) { + global $wgUser, $wgLang; - /** - * @return string an sqlquery - */ - function getSQL() { - $dbr =& wfGetDB( DB_SLAVE ); - list( $page, $page_restrictions ) = $dbr->tableNamesN( 'page', 'page_restrictions' ); - return "SELECT DISTINCT page_id, 'Protectedpages' as type, page_namespace AS namespace, page_title as title, " . - "page_title AS value, pr_level, pr_expiry " . - "FROM $page, $page_restrictions WHERE page_id = pr_page AND pr_user IS NULL "; - } + wfProfileIn( __METHOD__ ); - /** - * Make link to the page, and add the protection levels. - * - * @param $skin Skin to be used - * @param $result Result row - * @return string - */ - function formatResult( $skin, $result ) { - global $wgLang; - $title = Title::makeTitleSafe( $result->namespace, $result->title ); + static $skin=null; + + if( is_null( $skin ) ) + $skin = $wgUser->getSkin(); + + $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); $link = $skin->makeLinkObj( $title ); $description_items = array (); - $protType = wfMsg( 'restriction-level-' . $result->pr_level ); + $protType = wfMsg( 'restriction-level-' . $row->pr_level ); $description_items[] = $protType; $expiry_description = ''; - if ( $result->pr_expiry != 'infinity' && strlen($result->pr_expiry) ) { - $expiry = Block::decodeExpiry( $result->pr_expiry ); + if ( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) { + $expiry = Block::decodeExpiry( $row->pr_expiry ); $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) ); $description_items[] = $expiry_description; } - return wfSpecialList( $link, implode( $description_items, ', ' ) ); + wfProfileOut( __METHOD__ ); + + return '
  • ' . wfSpecialList( $link, implode( $description_items, ', ' ) ) . "
  • \n"; + } +} + +/** + * + * + */ +class ProtectedPagesPager extends ReverseChronologicalPager { + public $mForm, $mConds; + + function __construct( $form, $conds = array() ) { + $this->mForm = $form; + $this->mConds = $conds; + parent::__construct(); + } + + function getStartBody() { + wfProfileIn( __METHOD__ ); + # Do a link batch query + $this->mResult->seek( 0 ); + $lb = new LinkBatch; + + while ( $row = $this->mResult->fetchObject() ) { + $name = str_replace( ' ', '_', $row->page_title ); + $lb->add( $row->page_namespace, $name ); + } + + $lb->execute(); + wfProfileOut( __METHOD__ ); + return ''; + } + + function formatRow( $row ) { + $block = new Block; + return $this->mForm->formatRow( $row ); + } + + function getQueryInfo() { + $conds = $this->mConds; + $conds[] = 'pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ); + $conds[] = 'page_id=pr_page'; + return array( + 'tables' => array( 'page_restrictions', 'page' ), + 'fields' => 'page_id, ' . $this->mDb->tableName( 'page_restrictions' ) . '.*, page_title,page_namespace', + 'conds' => $conds, + 'options' => array( 'GROUP BY' => 'page_id' ), + ); + } + + function getIndexField() { + return 'pr_id'; } } @@ -86,11 +132,9 @@ function wfSpecialProtectedpages() { list( $limit, $offset ) = wfCheckLimits(); - $depp = new ProtectedPagesPage(); - - Title::purgeExpiredRestrictions(); + $ppForm = new ProtectedPagesForm(); - return $depp->doQuery( $offset, $limit ); + $ppForm->showList(); } ?> diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 984531ad00..e03cc60108 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1528,6 +1528,8 @@ The [http://meta.wikimedia.org/wiki/Help:Job_queue job queue] length is '''$7''' 'protectedpages' => 'Protected pages', 'protectedpages-summary' => '', 'protectedpagestext' => 'The following pages are protected from moving or editing', +'protectedpagesline' => '$1 ($2), expiry $3', +'protectedpagesempty' => 'No pages are currently protected', 'listusers' => 'User list', 'listusers-summary' => '', 'specialpages' => 'Special pages', -- 2.20.1